/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package simhya.matheval;
import simhya.matheval.function.FunctionDefinition;
/**
 *
 * @author Luca
 */
public class DynamicFunctionNode extends FunctionNode {

    public DynamicFunctionNode(FunctionDefinition function, int numberOfChildren) {
        super(function,numberOfChildren);
    }


   

   @Override
    void computeValue() {
        double[] arguments = new double[super.numberOfChildren];
        for (int i=0;i<super.numberOfChildren;i++) {
            children[i].computeValue();
            arguments[i] = children[i].value;
        }
        super.value = function.compute(arguments);
    }

    @Override
    void computeValue(SymbolArray varReference) {
        double[] arguments = new double[super.numberOfChildren];
        for (int i=0;i<super.numberOfChildren;i++) {
            children[i].computeValue(varReference);
            arguments[i] = children[i].value;
        }
        super.value = function.compute(arguments);
    }

    @Override
    void computeValue(int evaluationCode) {
        double[] arguments = new double[super.numberOfChildren];
        if (random || super.evaluationCode != evaluationCode) {
            super.evaluationCode = evaluationCode;
            for (int i=0;i<super.numberOfChildren;i++) {
                children[i].computeValue(evaluationCode);
                arguments[i] = children[i].value;
            }
            super.value = function.compute(arguments);
        }
    }

    @Override
    void computeValue(SymbolArray varReference, int evaluationCode) {
        double[] arguments = new double[super.numberOfChildren];
        if (random || super.evaluationCode != evaluationCode) {
            super.evaluationCode = evaluationCode;
            for (int i=0;i<super.numberOfChildren;i++) {
                children[i].computeValue(varReference,evaluationCode);
                arguments[i] = children[i].value;
            }
            super.value = function.compute(arguments);
        }
    }



}
